<template>
  <button class="the-button" :class="[
    `the-button--${type}`,
    `the-button--${size}`,
    { 'the-button--disabled': disabled },
    { 'the-button--plain': plain },
    { 'the-button--round': round },
    { 'the-button--circle': circle },
  ]" :style="customStyle" :disabled="disabled" @click="handleClick">
    <span class="the-button__content">
      <slot></slot>
    </span>
    <div class="the-button__shine"></div>
    <div class="the-button__glow"></div>
  </button>
</template>

<script>
export default {
  name: "theButton",
  props: {
    // 按鈕類型
    type: {
      type: String,
      default: "primary",
      validator: (value) =>
        ["primary", "success", "warning", "danger", "info", "text"].includes(
          value
        ),
    },
    // 按鈕尺寸
    size: {
      type: String,
      default: "default",
      validator: (value) => ["large", "default", "small"].includes(value),
    },
    // 是否禁用
    disabled: {
      type: Boolean,
      default: false,
    },
    // 是否樸素按鈕
    plain: {
      type: Boolean,
      default: false,
    },
    // 是否圓角按鈕
    round: {
      type: Boolean,
      default: false,
    },
    // 是否圓形按鈕
    circle: {
      type: Boolean,
      default: false,
    },
    // 自定義顏色
    color: {
      type: String,
      default: "",
    },
    // 自定義背景色
    backgroundColor: {
      type: String,
      default: "",
    },
    // 自定義邊框顏色
    borderColor: {
      type: String,
      default: "",
    },
    // 自定義寬度
    width: {
      type: [String, Number],
      default: "",
    },
    // 自定義高度
    height: {
      type: [String, Number],
      default: "",
    },
  },
  computed: {
    customStyle() {
      const style = {};

      if (this.color) {
        style.color = this.color;
      }

      if (this.backgroundColor) {
        style.background = this.backgroundColor;
      }

      if (this.borderColor) {
        style.borderColor = this.borderColor;
      }

      if (this.width) {
        style.width =
          typeof this.width === "number" ? `${this.width}px` : this.width;
      }

      if (this.height) {
        style.height =
          typeof this.height === "number" ? `${this.height}px` : this.height;
      }

      return style;
    },
  },
  methods: {
    handleClick(event) {
      if (!this.disabled) {
        this.$emit("click", event);
      }
    },
  },
};
</script>

<style scoped lang="scss">
.the-button {
  position: relative;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  align-self: center;
  width: auto;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  background: $dark-gold;
  border: 1px solid $dark-gold;
  color: $pure-white;
  text-align: center;
  box-sizing: border-box;
  outline: none;
  margin: 0;
  font-weight: 500;
  padding: 8px 16px;
  font-size: 14px;
  border-radius: 4px;
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  user-select: none;

  // 保留原有的特效樣式
  box-shadow: 0 4px 15px rgba(200, 169, 126, 0.3), 0 2px 8px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);

  // 内部发光效果
  &::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg,
        rgba(255, 255, 255, 0.1) 0%,
        transparent 50%);
    border-radius: inherit;
    pointer-events: none;
  }

  &__content {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    will-change: transform;
  }

  // 光泽效果
  &__shine {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg,
        transparent 30%,
        rgba(255, 255, 255, 0.3) 50%,
        transparent 70%);
    transform: translateX(-100%) translateY(-100%) rotate(45deg);
    transition: transform 0.6s ease;
    pointer-events: none;
  }

  // 外部光暈
  &__glow {
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(135deg, $gold-hover, $gold-accent);
    border-radius: inherit;
    opacity: 0;
    z-index: -1;
    transition: opacity 0.3s ease;
    filter: blur(8px);
  }

  // 懸停效果
  &:hover:not(.the-button--disabled) {
    background: $gold-hover;
    border-color: $gold-hover;
    transform: translateY(-2px) scale3d(1.02, 1.02, 1);
    box-shadow: 0 8px 25px rgba(200, 169, 126, 0.4),
      0 4px 15px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.2);

    .the-button__content {
      transform: scale3d(0.98, 0.98, 1);
    }

    .the-button__shine {
      transform: translateX(100%) translateY(100%) rotate(45deg);
    }

    .the-button__glow {
      opacity: 0.6;
    }
  }

  // 點擊效果
  &:active:not(.the-button--disabled) {
    background: $dark-gold;
    border-color: $dark-gold;
    transform: translateY(-1px) scale3d(0.98, 0.98, 1);
    box-shadow: 0 4px 15px rgba(200, 169, 126, 0.3),
      0 2px 8px rgba(0, 0, 0, 0.2), inset 0 2px 4px rgba(0, 0, 0, 0.1);

    .the-button__content {
      transform: scale3d(1.02, 1.02, 1);
    }
  }

  // 尺寸變體
  &--large {
    padding: 10px 20px;
    font-size: 16px;
    border-radius: 4px;
  }

  &--small {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 3px;
  }

  // 樣式變體
  &--success {
    background: $emerald;
    border-color: $emerald;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3), 0 2px 8px rgba(0, 0, 0, 0.1),
      inset 0 1px 0 rgba(255, 255, 255, 0.1);

    &:hover:not(.the-button--disabled) {
      background: #66bb6a;
      border-color: #66bb6a;
      box-shadow: 0 8px 25px rgba(76, 175, 80, 0.4),
        0 4px 15px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    }

    &:active:not(.the-button--disabled) {
      background: #388e3c;
      border-color: #388e3c;
    }
  }

  &--warning {
    background: $amber;
    border-color: $amber;
    box-shadow: 0 4px 15px rgba(255, 183, 77, 0.3), 0 2px 8px rgba(0, 0, 0, 0.1),
      inset 0 1px 0 rgba(255, 255, 255, 0.1);

    &:hover:not(.the-button--disabled) {
      background: #ffcc02;
      border-color: #ffcc02;
      box-shadow: 0 8px 25px rgba(255, 183, 77, 0.4),
        0 4px 15px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    }

    &:active:not(.the-button--disabled) {
      background: #ff8f00;
      border-color: #ff8f00;
    }
  }

  &--danger {
    background: $ruby;
    border-color: $ruby;
    box-shadow: 0 4px 15px rgba(211, 47, 47, 0.3), 0 2px 8px rgba(0, 0, 0, 0.1),
      inset 0 1px 0 rgba(255, 255, 255, 0.1);

    &:hover:not(.the-button--disabled) {
      background: #ef5350;
      border-color: #ef5350;
      box-shadow: 0 8px 25px rgba(211, 47, 47, 0.4),
        0 4px 15px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    }

    &:active:not(.the-button--disabled) {
      background: #c62828;
      border-color: #c62828;
    }
  }

  &--info {
    background: $disabled;
    border-color: $disabled;
    box-shadow: 0 4px 15px rgba(158, 158, 158, 0.3),
      0 2px 8px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.1);

    &:hover:not(.the-button--disabled) {
      background: #bdbdbd;
      border-color: #bdbdbd;
      box-shadow: 0 8px 25px rgba(158, 158, 158, 0.4),
        0 4px 15px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    }

    &:active:not(.the-button--disabled) {
      background: #757575;
      border-color: #757575;
    }
  }

  &--text {
    background: transparent;
    border: 1px solid transparent;
    color: $gold-accent;
    box-shadow: none;

    &:hover:not(.the-button--disabled) {
      background: rgba(200, 169, 126, 0.1);
      color: $gold-hover;
    }

    &:active:not(.the-button--disabled) {
      background: rgba(200, 169, 126, 0.2);
      color: $dark-gold;
    }
  }

  // 樸素按鈕
  &--plain {
    background: $pure-white;
    border-color: $ivory;
    color: $slate;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

    &:hover:not(.the-button--disabled) {
      background: $sapphire;
      border-color: $sapphire;
      color: $pure-white;
    }

    &.the-button--success {
      color: $emerald;
      border-color: #a5d6a7;
      background: #e8f5e8;

      &:hover:not(.the-button--disabled) {
        background: $emerald;
        border-color: $emerald;
        color: $pure-white;
      }
    }

    &.the-button--warning {
      color: $amber;
      border-color: #ffe082;
      background: #fff8e1;

      &:hover:not(.the-button--disabled) {
        background: $amber;
        border-color: $amber;
        color: $pure-white;
      }
    }

    &.the-button--danger {
      color: $ruby;
      border-color: #ffcdd2;
      background: #ffebee;

      &:hover:not(.the-button--disabled) {
        background: $ruby;
        border-color: $ruby;
        color: $pure-white;
      }
    }

    &.the-button--info {
      color: $disabled;
      border-color: #e0e0e0;
      background: $ivory;

      &:hover:not(.the-button--disabled) {
        background: $disabled;
        border-color: $disabled;
        color: $pure-white;
      }
    }
  }

  // 圓角按鈕
  &--round {
    border-radius: 20px;
  }

  // 圓形按鈕
  &--circle {
    border-radius: 50%;
    padding: 12px;
    width: 40px;
    height: 40px;

    &.the-button--large {
      width: 48px;
      height: 48px;
      padding: 16px;
    }

    &.the-button--small {
      width: 32px;
      height: 32px;
      padding: 8px;
    }
  }

  // 禁用狀態
  &--disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

    .the-button__shine {
      transform: translateX(-100%) translateY(-100%) rotate(45deg);
    }

    .the-button__glow {
      opacity: 0;
    }
  }
}

// 響應式設計
@media (max-width: 768px) {
  .the-button {
    padding: 8px 14px;
    font-size: 13px;

    &--small {
      padding: 6px 10px;
      font-size: 11px;
    }

    &--large {
      padding: 10px 16px;
      font-size: 15px;
    }

    &--circle {
      width: 36px;
      height: 36px;
      padding: 10px;

      &.the-button--large {
        width: 44px;
        height: 44px;
        padding: 14px;
      }

      &.the-button--small {
        width: 28px;
        height: 28px;
        padding: 6px;
      }
    }
  }
}
</style>
